package com.example.exam.sysDictInfo.service;

import com.example.exam.db.PageInfoBean;
import com.example.exam.sysDictInfo.dao.SysDictInfoDao;
import com.example.exam.sysDictInfo.model.SysDictInfoBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysDictInfoService {
    @Autowired
    SysDictInfoDao sdid;
    /**
     * @Description:添加字典信息
     * @Param: [sdib]
     * @return: java.lang.Integer
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public Integer insertDict(SysDictInfoBean sdib){
        Integer i=sdid.add(sdib);
        if(i>0){
            return 1;
        }else{
            return -1;
        }
    }/**
     * @Description:删除字典信息
     * @Param: [id]
     * @return: java.lang.Integer
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public Integer deleteDict(Integer id){
        Integer i=sdid.deleteById(id);
        if(i>0){
            return 1;
        }else{
            return -1;
        }
    }
    /**
     * @Description:获取字典信息列表数据
     * @Param: [pageNo, pageSize, name]
     * @return: com.example.exam.db.PageInfoBean
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public PageInfoBean toList(Integer pageNo, Integer pageSize, String name) {
        try {
            PageInfoBean page = new PageInfoBean();
            page.setPerPage(pageSize);
            if(pageNo != null) {
                page.setCurPage(pageNo);
            }
            PageInfoBean pageInfo = sdid.getListByTitle(page,name);
            return pageInfo;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * @Description:查询一条字典数据
     * @Param: [id]
     * @return: com.example.exam.sysDictInfo.model.SysDictInfoBean
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public SysDictInfoBean selectOneDict(Integer id){
        SysDictInfoBean sdib=sdid.findById(id);
        if(sdib!=null){
            return sdib;
        }else {
            return null;
        }
    }
    /**
     * @Description:修改字典数据
     * @Param: [sdib]
     * @return: java.lang.Integer
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public Integer updateDict(SysDictInfoBean sdib){
        Integer i=sdid.updateAllFieldById(sdib);
        if(i>0){
            return 1;
        }else{
            return -1;
        }
    }
    /**
     * @Description:查询父级字典
     * @Param: []
     * @return: java.util.List
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public List findParentDict(){
        List list=sdid.findParentDict();
        if (list==null){
            return null;
        }else{
            return list;
        }
    }
}
